#!/bin/bash

source main-var.sh
export buildAt="$(date '+%Y-%m-%d %H:%M:%S')"

p=$(echo $gitCloneUrl | rev | cut -d '/'  -f 1 | rev | cut -d '.' -f 1)

function cp_res(){
    if [ -d code/deploy-shell-res ]; then
      echo "使用项目中的 deploy-shell-res 脚本资源!"
      cp -rf code/deploy-shell-res/.  ./
    fi
}


echo "git clone --depth=1  --single-branch -b $gitBranch $gitCloneUrl" code
git clone --depth=1  --single-branch -b $gitBranch $gitCloneUrl code

if [ $? -ne 0 ]; then
  echo -e "\n"`date "+%Y-%m-%d %H:%M:%S"` "克隆失败!!!"
  exit 1
fi


cd code
echo ""  >> ../main-var.sh
echo  "export gitCommitId=\"$(git rev-parse HEAD)\""  >> ../main-var.sh
echo "export gitCommitAt=\"$(git log -1 --pretty=format:'%ai')\""  >> ../main-var.sh
echo "export gitCommitAuthor=\"$(git log -1 --pretty=format:'%an <%ae>')\""  >> ../main-var.sh
cd -


cp_res

echo -e "\n"`date "+%Y-%m-%d %H:%M:%S"` "克隆成功"
